﻿/*
  In App.xaml:
  <Application.Resources>
      <vm:ViewModelLocatorTemplate xmlns:vm="clr-namespace:HRM.ViewModel"
                                   x:Key="Locator" />
  </Application.Resources>
  
  In the View:
  DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
*/

using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Ioc;
using Microsoft.Practices.ServiceLocation;
using HRM.Model;
using GalaSoft.MvvmLight.Messaging;
using System.Collections.Generic;

namespace HRM.ViewModel
{
    /// <summary>
    /// This class contains static references to all the view models in the
    /// application and provides an entry point for the bindings.
    /// <para>
    /// See http://www.galasoft.ch/mvvm
    /// </para>
    /// </summary>
    public class ViewModelLocator
    {
        static ViewModelLocator()
        {
            ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

            if (ViewModelBase.IsInDesignModeStatic)
            {
                //Đắng ký design servicer cho interface tương ứng
                SimpleIoc.Default.Register<IProjectService, Design.DesignProjectService>();
                SimpleIoc.Default.Register<IFunction, Design.DesignFunctionService>();
                SimpleIoc.Default.Register<IDepartmentService, Design.DesignDeparmentService>();
                SimpleIoc.Default.Register<IEntityService<TrinhDoHocVan>, Design.DesignEducationService>();
            }
            else
            {
                SimpleIoc.Default.Register<IProjectService, ProjectService>();
                SimpleIoc.Default.Register<IFunction, FunctionService>();
                SimpleIoc.Default.Register<IUserService, UserService>();
                SimpleIoc.Default.Register<IDepartmentService, SearchDepartmentService>();
                SimpleIoc.Default.Register<IAuthenticationService, AuthenticationService>();
                SimpleIoc.Default.Register<IEntityService<PhongBan>, DepartmentService>();
                SimpleIoc.Default.Register<IEntityService<TrinhDoHocVan>, EducationService>();
                SimpleIoc.Default.Register<IEntityService<ChucVu>, RegencyService>();
                SimpleIoc.Default.Register<IEntityService<DMChungChi>, CategoryCertificateService>();
                SimpleIoc.Default.Register<IEntityService<LoaiLuongThuong>, PieceSalaryBonusService>();
                SimpleIoc.Default.Register<IEntityService<NhomNguoiDung>, GroupUserService>();
                SimpleIoc.Default.Register<IEntityService<NguoiSuDung>, UserEntityService>();
                SimpleIoc.Default.Register<IEntityService<NhanVien>, StaffService>();
                SimpleIoc.Default.Register<IEntityService<QuaTrinhCongTac>, WorkingHistoryService>();
                SimpleIoc.Default.Register<IEntityService<BangLuong>, SalaryService>();
                SimpleIoc.Default.Register<IEntityService<ThoiViec>, ResignService>();
                SimpleIoc.Default.Register<IEntityService<ChungChi>, CertificateService>();
                SimpleIoc.Default.Register<IEntityService<KinhNghiem>, ExperienceService>();
                SimpleIoc.Default.Register<IEntityService<ThamGiaDuAn>, ProjectParticipantService>();
            }

            //Đăng ký ViewModel vào IOC container
            SimpleIoc.Default.Register<MainViewModel>();
            SimpleIoc.Default.Register<ProjectViewModel>();
            SimpleIoc.Default.Register<FunctionViewModel>();
            SimpleIoc.Default.Register<LoginViewModel>();
            SimpleIoc.Default.Register<DepartmentViewModel>();
            SimpleIoc.Default.Register<EducationViewModel>();
            SimpleIoc.Default.Register<RegencyViewModel>();
            SimpleIoc.Default.Register<CategoryCertificateViewModel>();
            SimpleIoc.Default.Register<PieceSalaryBonusViewModel>();
            SimpleIoc.Default.Register<GroupUserViewModel>();
            SimpleIoc.Default.Register<ChooseGroupViewModel>();
            SimpleIoc.Default.Register<UserViewModel>();
            SimpleIoc.Default.Register<StaffViewModel>();
            SimpleIoc.Default.Register<WorkingHistoryDialogViewModel>();
            SimpleIoc.Default.Register<SalaryViewModel>();
            SimpleIoc.Default.Register<ExperienceViewModel>();
            SimpleIoc.Default.Register<ResignViewModel>();
            SimpleIoc.Default.Register<ProjectParticipantViewModel>();
            SimpleIoc.Default.Register<CertificateViewModel>();
        }

        /// <summary>
        /// Gets the Main property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public MainViewModel Main
        {
            get
            {
                return ServiceLocator.Current.GetInstance<MainViewModel>();
            }
        }

        public LoginViewModel Login
        {
            get
            {
                return ServiceLocator.Current.GetInstance<LoginViewModel>();
            }
        }

        public ChooseGroupViewModel ChooseGroupDialog
        {
            get
            {
                return ServiceLocator.Current.GetInstance<ChooseGroupViewModel>();
            }
        }

        public WorkingHistoryDialogViewModel WorkingHistoryDialog
        {
            get
            {
                return ServiceLocator.Current.GetInstance<WorkingHistoryDialogViewModel>();
            }
        }

        public CertificateViewModel CertificateDialog
        {
            get
            {
                return ServiceLocator.Current.GetInstance<CertificateViewModel>();
            }
        }

        public SalaryViewModel SalaryDialog
        {
            get
            {
                return ServiceLocator.Current.GetInstance<SalaryViewModel>();
            }
        }

        public ProjectParticipantViewModel PPDialog
        {
            get
            {
                return ServiceLocator.Current.GetInstance<ProjectParticipantViewModel>();
            }
        }

        public ExperienceViewModel ExDialog
        {
            get
            {
                return ServiceLocator.Current.GetInstance<ExperienceViewModel>();
            }
        }

        public ResignViewModel ResignDialog
        {
            get
            {
                return ServiceLocator.Current.GetInstance<ResignViewModel>();
            }
        }

        /// <summary>
        /// Cleans up all the resources.
        /// </summary>
        public static void Cleanup()
        {
            SimpleIoc.Default.Unregister<NguoiSuDung>();
            SimpleIoc.Default.Unregister<List<ChucNang>>();
        }
    }
}